home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / domacnost a kancelar / joomla / Joomla_1.5.4-Stable-Full_Package.exe / plugins / authentication / joomla.php < prev    next >
PHP Script  |  2008-07-06  |  3KB  |  107 lines

  1. <?php
  2. /**
  3. * @version        $Id: joomla.php 10381 2008-06-01 03:35:53Z pasamio $
  4. * @package        Joomla
  5. * @subpackage    JFramework
  6. * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  7. * @license        GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // Check to ensure this file is included in Joomla!
  16. defined('_JEXEC') or die( 'Restricted access' );
  17.  
  18. jimport( 'joomla.plugin.plugin' );
  19.  
  20. /**
  21.  * Joomla Authentication plugin
  22.  *
  23.  * @author Louis Landry <louis.landry@joomla.org>
  24.  * @package        Joomla
  25.  * @subpackage    JFramework
  26.  * @since 1.5
  27.  */
  28. class plgAuthenticationJoomla extends JPlugin
  29. {
  30.  
  31.     /**
  32.      * Constructor
  33.      *
  34.      * For php4 compatability we must not use the __constructor as a constructor for plugins
  35.      * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  36.      * This causes problems with cross-referencing necessary for the observer design pattern.
  37.      *
  38.      * @param object $subject The object to observe
  39.      * @param array  $config  An array that holds the plugin configuration
  40.      * @since 1.5
  41.      */
  42.     function plgAuthenticationJoomla(& $subject, $config) {
  43.         parent::__construct($subject, $config);
  44.     }
  45.  
  46.     /**
  47.      * This method should handle any authentication and report back to the subject
  48.      *
  49.      * @access    public
  50.      * @param   array     $credentials Array holding the user credentials
  51.      * @param     array   $options     Array of extra options
  52.      * @param    object    $response     Authentication response object
  53.      * @return    boolean
  54.      * @since 1.5
  55.      */
  56.     function onAuthenticate( $credentials, $options, &$response )
  57.     {
  58.         jimport('joomla.user.helper');
  59.  
  60.         // Joomla does not like blank passwords
  61.         if (empty($credentials['password']))
  62.         {
  63.             $response->status = JAUTHENTICATE_STATUS_FAILURE;
  64.             $response->error_message = 'Empty password not allowed';
  65.             return false;
  66.         }
  67.  
  68.         // Initialize variables
  69.         $conditions = '';
  70.  
  71.         // Get a database object
  72.         $db =& JFactory::getDBO();
  73.  
  74.         $query = 'SELECT `id`, `password`, `gid`'
  75.             . ' FROM `#__users`'
  76.             . ' WHERE username=' . $db->Quote( $credentials['username'] )
  77.             ;
  78.         $db->setQuery( $query );
  79.         $result = $db->loadObject();
  80.  
  81.  
  82.         if($result)
  83.         {
  84.             $parts    = explode( ':', $result->password );
  85.             $crypt    = $parts[0];
  86.             $salt    = @$parts[1];
  87.             $testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
  88.  
  89.             if ($crypt == $testcrypt) {
  90.                 $user = JUser::getInstance($result->id); // Bring this in line with the rest of the system
  91.                 $response->email = $user->email;
  92.                 $response->fullname = $user->name;
  93.                 $response->status = JAUTHENTICATE_STATUS_SUCCESS;
  94.                 $response->error_message = '';
  95.             } else {
  96.                 $response->status = JAUTHENTICATE_STATUS_FAILURE;
  97.                 $response->error_message = 'Invalid password';
  98.             }
  99.         }
  100.         else
  101.         {
  102.             $response->status = JAUTHENTICATE_STATUS_FAILURE;
  103.             $response->error_message = 'User does not exist';
  104.         }
  105.     }
  106. }
  107.